//
//  MPMarkStep.m
//  MarkPlatform
//
//  Created by xiao6 on 2018/1/8.
//  Copyright © 2018年 AT. All rights reserved.
//

#import "MPMarkStep.h"


@implementation MPMarkModel
+ (instancetype)modelWithPoint:(CGPoint)point {
    MPMarkModel *model = [[self alloc] init];
    model.way = MPMarkTypePoint;
    model.viewRect = CGRectMake(point.x, point.y, 0, 0);
    model.rect = CGRectMake(point.x, point.y, 0, 0);
    return model;
}
+ (instancetype)modelWithRect:(CGRect)rect {
    MPMarkModel *model = [[self alloc] init];
    model.way = MPMarkTypeRect;
    model.viewRect = rect;
    model.rect = rect;
    return model;
}
@end

@implementation MPMarkStep
- (NSMutableArray<MPMarkModel *> *)markModels {
    if (!_markModels) {
        _markModels = [NSMutableArray array];
    }
    return _markModels;
}
- (NSString *)stepCoordinateWithScale:(CGFloat)scale {
    NSMutableString *str = [[NSMutableString alloc] init];
    for (MPMarkModel *model in self.markModels) {
        if (model.way == MPMarkTypePoint) {
            if (str.length) {
                [str appendString:@";"];
            }
            [str appendFormat:@"%.0f,%.0f", model.viewRect.origin.x * scale, model.viewRect.origin.y * scale];
        }
        else if (model.way == MPMarkTypeRect) {
            if (str.length) {
                [str appendString:@";"];
            }
            [str appendFormat:@"%.0f,%.0f,%.0f,%.0f", model.viewRect.origin.x * scale, model.viewRect.origin.y * scale, model.viewRect.size.width * scale, model.viewRect.size.height * scale];
        }
    }
    return str;
}
@end
